package com.power.using.sharlockchat.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.power.using.sharlockchat.R;
import com.power.using.sharlockchat.base.BaseBackFragment;
import com.power.using.sharlockchat.bean.ShowBean;
import com.zhy.http.okhttp.OkHttpUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 聪明一只哈 on 2019/3/7.
 * Time: 2019/3/7  15:04
 */
public class SolvedDetialFragment extends BaseBackFragment {

    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    Unbinder unbinder;
    @BindView(R.id.tv_show_name)
    TextView tvShowName;
    @BindView(R.id.tv_show_description)
    TextView tvShowDescription;
    private ShowBean showBean;

    public static SolvedDetialFragment newInstance(ShowBean showBean) {
        Bundle args = new Bundle();
        args.putSerializable("showbean", showBean);
        SolvedDetialFragment fragment = new SolvedDetialFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_solvedetial, container, false);
        unbinder = ButterKnife.bind(this, view);
        intView(view);
        return view;


    }

    private void intView(View view) {

        toolbarTitle.setText("已解决问题展示");
        //tv中的文本内容过多时可以上下滑动
        tvShowDescription.setMovementMethod(ScrollingMovementMethod.getInstance());

        Bundle arguments = getArguments();
        if (arguments != null) {
            showBean = (ShowBean) arguments.getSerializable("showbean");
        }
        tvShowName.setText(showBean.getTitle());
        tvShowDescription.setText(showBean.getDescription());
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
        OkHttpUtils.getInstance().cancelTag(this);
        cancelLoadingDialog();

    }
}

